// src/utils/request.js
import Taro from '@tarojs/taro';

const baseUrl = 'http://localhost:8080'; //  API 基础 URL

const request = (url, options) => {
  return new Promise((resolve, reject) => {
    Taro.request({
      url: baseUrl + url,
      ...options,
      header: {
        'Content-Type': 'application/json',
        // 'Authorization': 'Bearer your_token', // 示例：添加全局的 Authorization 头
        // ...options.header,
      },
      success: res => {
        if (res.statusCode >= 200 && res.statusCode < 300) {
          resolve(res.data);
        } else {
          reject(new Error(`HTTP error! status: ${res.statusCode}`));
        }
      },
      fail: err => {
        reject(err);
      },
    });
  });
};

export default request;
